// import BMap from 'BMap';
// import BMapSymbolSHAPEPOINT from 'BMap_Symbol_SHAPE_POINT';
define([
    './themes/lang/' + window.YUFP_SYS_CONFIG.language + '/pages/example/map/map.js',
    './custom/widgets/js/yufpOrgTree.js',
    './custom/plugins/YufpMgrSelector.js',
    './custom/widgets/js/yufpExtTree.js'
], function (require, exports) {
    // page加载完成后调用ready方法
    exports.ready = function (hashCode, data, cite) {
        yufp.lookup.reg('GRID_TYPE,GRID_LEVEL,GRID_BUILDING_TYPE,KEYMAN_TYPE,KEYMAN_KNOW_DEGREE');
        yufp.custom.vue({
            el: '#map1',
            data: function () {
                var me = this;
                return {
                    gridModifyButton: !yufp.session.checkCtrl('gridModify'), //网格修改  用于关闭除总行以外的修改网格权限，造成网格经纬度改变，需要重新跑数
                    gridInfoButton: !yufp.session.checkCtrl('gridInfoModify'), //基础信息修改
                    distributeMgrButton: !yufp.session.checkCtrl('distributeMgr'), // 分配客户经理
                    keyManTableplusButton: !yufp.session.checkCtrl('keyManTableplus'), // 关键人信息新增
                    keyManTableminusButton: !yufp.session.checkCtrl('keyManTableminus'), // 关键人信息删除
                    keyManTableeditButton: !yufp.session.checkCtrl('keyManTableedit'), // 关键人信息修改
                    // buildTableplusButton: !yufp.session.checkCtrl('buildTableplus'), // 建筑物信息新增
                    buildTableminusButton: !yufp.session.checkCtrl('buildTableminus'), // 建筑物信息删除
                    buildTableeditButton: !yufp.session.checkCtrl('buildTableedit'), // 分配客户经理修改
                    gridInfoModifyButton: !yufp.session.checkCtrl('gridInfoModifySub'), // 基础信息修改提交
                    unitPriceDis:true,
                    unitNumberDis:true,
                    map: null,
                    flag: true,
                    heightOrg: yufp.custom.viewSize().height - 152,
                    treeUrlRel: backend.appOcaService + '/api/util/getorg',
                    dataRoot: {orgId: yufp.session.org.id, orgName: yufp.session.org.name},
                    treeWith: 5,
                    dataParams: {orgSts: 'A', lazy: true},
                    // dataUrl: '',
                    drawingManager: null,
                    cityName: '',
                    polygon: null,
                    modifyPolygon: null,
                    stsOptions: null,
                    secOptions: null,
                    configType: 'CREATE',
                    gridVisible: false,
                    createGridFormdata: {},
                    createFormdata: {},
                    configdialogVisible: false,
                    chooseGridVisible: false,
                    gridInfoVisible: false,
                    buildInfoVisible: false,
                    mgrFPVisible: false,
                    keyManVisible: false,
                    GridTab: true, // 网格地图划分
                    GridInfoTab: true, // 网格信息配置
                    chooseGridFormdata: {},
                    keyManGridFormdata: {},
                    buildInfoGridFormdata: {},
                    mgrFPFormdata: {},
                    mgrFPVisibleForm: {},
                    mgrFPGridId: '',
                    keymantype: '',
                    keymanname: '',
                    keymanphone: '',
                    gridBaseInfo: {},
                    showGridNameOrg: true,
                    showGridName: false,
                    showGridType: true,
                    showUpGridId: false,
                    showSec: false,
                    tabName: 'first',
                    keyManDataList:[],
                    buildDataList:[],
                    gridName: [],
                    gridId: "",
                    gridModifyName: '',
                    dataUrl: '/api/gridGeneral/gridTableSelect',
                    keyManDataUrl: '/api/gridGeneral/queryGridKeyManById',
                    udataParams: {},
                    girdInfoParams: {},
                    importDialogVisible: false,
                    buildDataUrl: '/api/gridGeneral/queryGridBuildById',
                    gridModifyId: '',
                    loadingA: false,
                    loadingB: false,
                    loadingC: false,
                    loadingD: false,
                    loadingE: false,
                    buildMap: {
                        update: '修改网格信息',
                        create: '创建网格信息',
                    },
                    keyManMap: {
                        update: '修改关键人信息',
                        create: '创建关键人信息',
                    },
                    buildInfoMap: {
                        update: '修改建筑物信息',
                        create: '创建建筑物信息',
                    },
                    dialogStatus: '',
                    styleOptions: {
                        strokeColor: "#1a1aff",    //边线颜色。
                        fillColor: "",      //填充颜色。当参数为空时，圆形将没有填充效果。
                        strokeWeight: 3,       //边线的宽度，以像素为单位。
                        strokeOpacity: 0.8,	   //边线透明度，取值范围0 - 1。
                        fillOpacity: 0.6,      //填充的透明度，取值范围0 - 1。
                        strokeStyle: 'solid' //边线的样式，solid或dashed。
                    },
                    styleOptionsLevel2: {
                        strokeColor: "#009900",    //边线颜色。
                        fillColor: "",      //填充颜色。当参数为空时，圆形将没有填充效果。
                        strokeWeight: 3,       //边线的宽度，以像素为单位。
                        strokeOpacity: 0.8,	   //边线透明度，取值范围0 - 1。
                        fillOpacity: 0.6,      //填充的透明度，取值范围0 - 1。
                        strokeStyle: 'dashed' //边线的样式，solid或dashed。
                    },
                    uploadAction: backend.appOcaService + '/api/gridGeneral/excel/import',
                    headers: {
                        'Authorization': 'Bearer' + yufp.service.getToken(),
                        'Content-Type': 'multipart/form-data'
                    },
                    rules: {
                        gridLevel: [
                            {required: true, message: '必填项', trigger: 'blur'}
                        ],
                        upGrid: [
                            {required: true, message: '必填项', trigger: 'blur'}
                        ],
                        gridName: [
                            {required: true, message: '必填项', trigger: 'blur'}
                        ],
                        upGridId: [
                            {required: true, message: '必填项', trigger: 'blur'}
                        ],
                        gridNameOrg: [
                            {required: true, message: '必填项', trigger: 'blur'}
                        ],
                        gridType: [
                            {required: true, message: '必填项', trigger: 'blur'}
                        ],
                        longitude: [
                            {required: true, message: '必填项', trigger: 'blur'}
                        ],
                        scenePro: [
                            {required: true, message: '必填项', trigger: 'blur'}
                        ],
                        buildName: [
                            {required: true, message: '必填项', trigger: 'blur'}
                        ],
                        latitude: [
                            {required: true, message: '必填项', trigger: 'blur'}
                        ],
                        sectionid: [
                            {required: true, message: '必填项', trigger: 'blur'}
                        ]
                    },
                };
            },
            computed: {
                action: function () {
                    var _this = this;
                    return yufp.service.getUrl({ url: _this.uploadAction });
                }
            },
            mounted() {
                this.tabName = this.GridTab ? 'first' : (this.GridInfoTab ? 'second' : '');
                // 百度地图API功能
                map = new BMap.Map("allmap");    // 创建Map实例
                map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);  // 初始化地图,设置中心点坐标和地图级别
                //添加地图类型控件
                map.addControl(new BMap.MapTypeControl({
                    mapTypes: [
                        BMAP_NORMAL_MAP,
                        BMAP_HYBRID_MAP
                    ]
                }));
                map.setCurrentCity("南京市");          // 设置地图显示的城市 此项是必须设置的
                map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
                // var geolocation = new Map.Geolocation();
                // geolocation.getCurrentPosition(function (r) {
                //     if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                //         map.centerAndZoom(new BMap.Point(r.point.lng, r.point.lat), 15);
                //     }
                // }, { enableHighAccuracy: true })
                // var point = new BMap.Point(116.331398,39.897445);
                // map.centerAndZoom(point,12);
                // map.enableScrollWheelZoom(true);
                // function myFun(result){
                //     var cityName = result.name;
                //     map.setCenter(cityName);
                //     // alert("当前定位城市:"+cityName);
                // }
                // var myCity = new BMap.LocalCity();
                // myCity.get(myFun);
                this.initData();



                //根据角色加载不同的下拉内容，且客户经理角色无法修改
                // var me = this;

                // yufp.lookup.bind('GRID_BUILDING_TYPE', function (data) {
                //     console.info('========================');
                //     console.info(data);
                //     this.stsOptions = data;
                // });

            },
            created(){
                this.initData();
            },
            methods: {
                onSuccess: function (response, file, fileList) {

                },
                onError: function (err, file, fileList) {
                },
                submitUpload: function () {
                    var _this = this;
                    var fileName = _this.$refs.upload.uploadFiles[0].name;
                    if (fileName.lastIndexOf('.') != -1) {
                        var fileType = (fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length)).toLowerCase();
                        var supportFile = new Array();
                        supportFile[0] = 'xls';
                        supportFile[1] = 'xlsx';
                        if ($.inArray(fileType, supportFile) < 0) {
                            _this.$message({ message: '不支持的文件类型' });
                            _this.$refs.upload.clearFiles();
                            return;
                        }
                    } else {
                        _this.$message({ message: '文件只支持xls,xlsx' });
                        _this.$refs.upload.clearFiles();
                        return;
                    }
                    this.$refs.upload.submit();
                },
                requireGridMap: function () {

                },
                uploadFn: function () {
                    this.importDialogVisible = true;
                },
                saveBuildInfo: function () {
                    var _this = this;
                    _this.loadingD = true;
                    var model = {};
                    console.info(this.buildInfoGridFormdata);
                    yufp.clone(_this.buildInfoGridFormdata, model);
                    model.gridId = _this.gridBaseInfo.id;
                    model.userName = yufp.session.userName;
                    console.info(model);
                    yufp.service.request({
                        method: 'POST',
                        url: '/api/gridGeneral/saveBuildInfoGridData',
                        data: model,
                        callback: function (code, message, response) {
                            if (response.code === '0000') {
                                _this.$message({message: '创建成功', type: 'success'});
                                _this.buildInfoVisible = false;
                                _this.buildInfoGridFormdata = {};
                                // _this.initData();
                                _this.$refs.buildTable.remoteData(_this.udataParams);
                                _this.buildInfoVisible = false;
                            } else {
                                _this.buildInfoVisible = false;
                                _this.$message({message: '创建失败', type: 'error'});
                            }
                            _this.loadingD = false;
                        }
                    });
                },
                saveMgrFP: function () {
                    var _this = this;
                    _this.loadingE = true;
                    var model = {};
                    console.info(this.mgrFPFormdata);
                    yufp.clone(_this.mgrFPFormdata, model);
                    model.gridId = _this.mgrFPGridId;
                    model.userName = yufp.session.userName;
                    yufp.service.request({
                        method: 'POST',
                        url: '/api/gridGeneral/saveMgrFPGridData',
                        data: model,
                        callback: function (code, message, response) {
                            if (code == 0 && response.data > 0) {
                                _this.$message({message: '分配成功', type: 'success'});
                            } else {
                                _this.$message({message: '分配失败', type: 'error'});
                            }
                            _this.mgrFPFormdata = {};
                            _this.mgrFPFormdata.userID = "";
                            _this.$refs.girdInfoTable.remoteData(_this.girdInfoParams);
                            _this.mgrFPGridId = "";
                            _this.mgrFPVisible = false;
                            _this.loadingE = false;
                        }
                    });
                },
                cancelMgrFn: function () {
                    this.mgrFPVisible = false;

                },
                saveKeyMan: function () {
                    var _this = this;
                    var model = {};
                    console.info(this.keyManGridFormdata);
                    yufp.clone(_this.keyManGridFormdata, model);
                    model.gridId = _this.gridBaseInfo.id;
                    model.userName = yufp.session.userName;
                    yufp.service.request({
                        method: 'POST',
                        url: '/api/gridGeneral/saveKeyManGridData',
                        data: model,
                        callback: function (code, message, response) {
                            if (code == 0 && response.data > 0) {
                                _this.$message({message: '创建成功', type: 'success'});
                                _this.gridVisible = false;
                                _this.keyManGridFormdata = {};
                                // _this.initData();
                                _this.$refs.keyManTable.remoteData(_this.keyManTable);
                                _this.keyManVisible = false;
                            } else {
                                _this.keyManVisible = false;
                                _this.$message({message: '创建失败', type: 'error'});
                            }
                        }
                    });
                },
                keyManTableplusFn: function () {
                    console.info("keyManTableplusFn");
                    this.dialogStatus = 'create';
                    this.keyManVisible = true;
                },
                keyManTableminusFn: function () {
                    console.info("keyManTableminusFn");
                    var rows = this.$refs.keyManTable.selections;
                    if (rows.length > 0) {
                        var id = '';
                        for (var i = 0; i < rows.length; i++) {
                            var row = rows[i];
                            id = id + ',' + row.id;
                        }
                        id = id.substr(1);
                        var vue = this;
                        this.$confirm('删除之后将无法恢复，请确认是否删除', '警告通知提醒', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(function () {
                            yufp.service.request({
                                method: 'DELETE',
                                data: {
                                    id: id
                                },
                                url: backend.appOcaService + '/api/gridGeneral/deletebatch?id=' + id,
                                callback: function (code, message, response) {
                                    if (response.code === '0000') {
                                        vue.$message.success(response.data);
                                    } else {
                                        vue.$message.warning(response.message);
                                    }
                                    vue.$refs.keyManTable.remoteData();
                                    vue.$refs.keyManTable.clearSelection();
                                }
                            });
                        });
                    } else {
                        this.$message({ message: '请先选择要删除的数据', type: 'warning' });
                        return;
                    }

                },
                keyManTableeditFn: function () {
                    var vm = this;
                    if (vm.$refs.keyManTable.selections.length != 1) {
                        vm.$message({ message: '请选择一条数据', type: 'warning' });
                        return;
                    }
                    vm.keyManGridFormdata.id= vm.$refs.keyManTable.selections[0].id;
                    vm.keyManGridFormdata.keymanType= vm.$refs.keyManTable.selections[0].keymantype;
                    vm.keyManGridFormdata.keymanName= vm.$refs.keyManTable.selections[0].keymanname;
                    vm.keyManGridFormdata.keymanPhone= vm.$refs.keyManTable.selections[0].keymanphone;
                    this.dialogStatus = 'update';
                    this.keyManVisible = true;
                },
                buildTableplusFn: function () {
                    console.info("buildTableplusFn");
                    // console.info(vm.keyManDataList);
                    // console.info("=========================");
                },
                buildTableminusFn: function () {
                    console.info("buildTableminusFn");
                    var rows = this.$refs.buildTable.selections;
                    if (rows.length > 0) {
                        var id = '';
                        for (var i = 0; i < rows.length; i++) {
                            var row = rows[i];
                            id = id + ',' + row.id;
                        }
                        id = id.substr(1);
                        var vue = this;
                        this.$confirm('删除之后将无法恢复，请确认是否删除', '警告通知提醒', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(function () {
                            yufp.service.request({
                                method: 'DELETE',
                                data: {
                                    id: id
                                },
                                url: backend.appOcaService + '/api/gridGeneral/deletebatchBuild?id=' + id,
                                callback: function (code, message, response) {
                                    if (response.code === '0000') {
                                        vue.$message.success(response.data);
                                    } else {
                                        vue.$message.warning(response.message);
                                    }
                                    vue.$refs.buildTable.remoteData();
                                    vue.$refs.buildTable.clearSelection();
                                }
                            });
                        });
                    } else {
                        this.$message({ message: '请先选择要删除的数据', type: 'warning' });
                        return;
                    }
                },
                buildTableeditFn: function () {
                    console.info("buildTableeditFn");
                    var vm = this;
                    if (vm.$refs.buildTable.selections.length != 1) {
                        vm.$message({ message: '请选择一条数据', type: 'warning' });
                        return;
                    }
                    vm.buildInfoGridFormdata.id= vm.$refs.buildTable.selections[0].id;
                    vm.buildInfoGridFormdata.unitName= vm.$refs.buildTable.selections[0].unitName;
                    vm.buildInfoGridFormdata.unitStorey= vm.$refs.buildTable.selections[0].unitStorey;
                    vm.buildInfoGridFormdata.custNum= vm.$refs.buildTable.selections[0].custNum;
                    this.dialogStatus = 'update';
                    this.buildInfoVisible = true;
                },
                //保存网格基本信息和关键人信息
                updateGridInfo: function () {
                    var _this = this;
                    _this.loadingC = true;
                    var model = {};
                    console.info(this.gridBaseInfo);
                    yufp.clone(_this.gridBaseInfo, model);
                    model.userName = yufp.session.userName;
                    console.info(model);
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/gridGeneral/updateGridInfoById',
                        method: 'POST',
                        // data: JSON.stringify(array),
                        data: model,
                        callback: function (code, message, response) {
                            if (code == 0 && response.code == 0) {
                                //获取上级网格名称和ID
                                console.info(response.data);
                                // console.info(response.data[0].id);
                                if(response.data.length>0){
                                    _this.$message({message: '修改成功', type: 'success'});
                                }
                            } else {
                                _this.$message({message: '修改失败', type: 'success'});
                            }
                            _this.gridInfoVisible = false;
                            _this.loadingC = false;
                        }
                    });
                },
                cancelFn: function () {
                    var _this = this;
                    _this.gridInfoVisible = false;
                    _this.keyManDataList = [];
                },
                cancelGridFn: function () {
                    var _this = this;
                    _this.configdialogVisible = false;
                    _this.gridVisible = false;
                    _this.chooseGridVisible = false;
                    _this.initData();
                },
                closeFn: function () {
                    var _this = this;
                    _this.gridInfoVisible = false;
                    _this.keyManDataList = [];
                },
                mgrFPFn: function () {
                    var _this = this;

                    var row = this.$refs.girdInfoTable.selections;
                    if (row.length !== 1) {
                        this.$message({ message: '请先选中一条数据', type: 'warning' });
                        return;
                    };
                    _this.mgrFPVisible = true;
                    _this.mgrFPGridId = _this.$refs.girdInfoTable.selections[0].id;
                },
                baseInfoClickFn: function () {
                    var _this = this;
                    var row = this.$refs.girdInfoTable.selections;
                    if (row.length !== 1) {
                        this.$message({ message: '请先选中一条数据', type: 'warning' });
                        return;
                    };
                    this.udataParams.condition=JSON.stringify({
                        gridId: row[0].id
                    });
                    console.info("------------------------");
                    console.info(row);
                    console.info(row[0].id);
                    this.gridInfoVisible=true;
                    _this.keyManDataList=[];
                    //基本信息查询
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/gridGeneral/queryGridInfoById',
                        method: 'get',
                        // data: JSON.stringify(array),
                        data: {
                            condition: JSON.stringify({
                                id: row[0].id,
                            })
                        },
                        callback: function (code, message, response) {
                            if (code == 0 && response.code == 0) {
                                //获取上级网格名称和ID
                                console.info(response.data);
                                console.info(response.data[0].id);
                                if(response.data.length>0){
                                    _this.gridBaseInfo.id=response.data[0].id;
                                    _this.gridBaseInfo.gridname=response.data[0].gridname;
                                    _this.gridBaseInfo.gridscenetype=response.data[0].gridscenetype;
                                    _this.gridBaseInfo.longitude=response.data[0].longitude;
                                    _this.gridBaseInfo.latitude=response.data[0].latitude;
                                    _this.gridBaseInfo.userName=response.data[0].userName;
                                    _this.gridBaseInfo.orgId=response.data[0].orgid;
                                    _this.gridBaseInfo.upGridName=response.data[0].pregridname;
                                    console.info("response.data[0].unitPrice=========");
                                    console.info(response.data[0].unitPrice);
                                    _this.gridBaseInfo.unitPrice=response.data[0].unitPrice==undefined?'':response.data[0].unitPrice;
                                    _this.gridBaseInfo.unitNumber=response.data[0].unitNumber==undefined?'':response.data[0].unitNumber;
                                    _this.gridBaseInfo.buildNum=response.data[0].buildNum==undefined?'':response.data[0].buildNum;
                                    _this.gridBaseInfo.residentPopu=response.data[0].residentPopu==undefined?'':response.data[0].residentPopu;
                                }
                            } else {
                                console.info("失败");
                            }
                        }
                    });
                    // yufp.service.request({
                    //     url: backend.msmFrontWebService + '/api/gridGeneral/queryGridKeyManById',
                    //     method: 'get',
                    //     // data: JSON.stringify(array),
                    //     data: {
                    //         condition: JSON.stringify({
                    //             gridId: row[0].id,
                    //         })
                    //     },
                    //     callback: function (code, message, response) {
                    //         if (code == 0 && response.code == 0) {
                    //             console.info(response.data);
                    //             for (var i = 0; i < response.data.length; i++) {
                    //                 _this.keyManDataList.push(response.data[i]);
                    //
                    //             }
                    //         } else {
                    //             console.info("失败");
                    //         }
                    //     }
                    // });
                    _this.$refs.buildTable.remoteData(_this.udataParams);
                    _this.$refs.keyManTable.remoteData(_this.udataParams);

                },
                //单元格点击后，显示input，并让input 获取焦点
                // handleCellClick:function(row, column, cell, event){
                //     emptransfer.addClass(cell,'current-cell');
                //     if(emptransfer.getChildElement(cell,3) !== 0){
                //         var _inputParentNode =emptransfer.getChildElement(cell,3);
                //         if(_inputParentNode.hasChildNodes()&& _inputParentNode.childNodes.length > 2) {
                //             var _inputNode = _inputParentNode.childNodes[2];
                //             if(_inputNode.tagName === 'INPUT'){
                //                 _inputNode.focus();
                //             }
                //         }
                //     }
                // },
                //input框失去焦点事件
                handleInputBlur:function(event){   //当 input 失去焦点 时,input 切换为 span，并且让下方 表格消失（注意，与点击表格事件的执行顺序）
                    var _event = event;
                    console.info('--------------------------------');
                    console.info(event.target);
                    console.info(this.keyManDataList);
                    // this.$refs.keyManTable.validate((valid) => {
                    //     if (valid) {
                    //         let data = this.formData.tableData
                    //         alert(JSON.stringify(data))
                    //     }
                    // })
                    // setTimeout(function(){
                    //     var _inputNode = _event.target;
                    //     if(emptransfer.getParentElement(_inputNode,4)!==0){
                    //         var _cellNode = emptransfer.getParentElement(_inputNode,4);
                    //         emptransfer.removeClass(_cellNode,'current-cell');
                    //         emptransfer.removeClass(_cellNode,'current-cell2');
                    //     }
                    // },200);
                },
                validate: function() {
                    this.$refs.yutable.validate(function(fields) {
                        console.log(fields);
                    },true);
                },
                clearValidate:  function() {
                    this.$refs.yutable.clearValidateMessage();
                },
                newData: function() {
                    var row = {
                        date: '',
                        status: '',
                        address: ''
                    };
                    var flag = false;
                    // 校验表格数据
                    this.$refs.yutable.validate(function(fields) {
                        console.log("fields", fields);
                        if(!fields){
                            flag = true;
                        }
                    });
                    // 校验通过添加数据
                    if(flag){
                        this.tableData1.push(row);
                        this.$refs.yutable.setCurrentRow(row);
                    }
                },

                buildTableFn: function () {
                    if (this.buildDataList == undefined) {
                        this.buildDataList = new Array();
                    }
                    let obj = {};
                    obj.buildName = "1";
                    obj.num = "1";
                    obj.unitnumber = '18';
                    this.buildDataList.push(obj);
                },
                searchFn: function () {
                    var vm = this;
                    var param = {
                        condition: JSON.stringify({
                            gridName: vm.$refs.gridInfoSearch.formdata.gridName,
                            gridType: vm.$refs.gridInfoSearch.formdata.gridType,
                            orgId: vm.$refs.gridInfoSearch.formdata.orgId,
                            userName: vm.$refs.gridInfoSearch.formdata.userName,
                            girdLevel: vm.$refs.gridInfoSearch.formdata.girdLevel
                        })
                    };
                    this.$refs.girdInfoTable.remoteData(param);
                },
                nodeClickFn: function (node, obj, nodeComp) {
                    console.info(node.orgId)
                    var vm = this;
                    if (node != '') {
                        var param = {
                            condition: JSON.stringify({
                                orgId: node.orgId,
                                orgLevel: node.orgLevel
                            })
                        };
                        vm.$refs.girdInfoTable.remoteData(param);
                    }
                },
                sureShow: function () {//根据选择内容定位gridId  此方法需根据  ->总行取全部1级网格及选择网格可修改  ->支行进行去起机构的全部二级网格，且选择的可修改
                    var _this = this;
                    var level = "2";
                    var sectionid = "";
                    if (yufp.session.roles[0].code == 'R0008' || yufp.session.roles[0].code == 'R0007') {
                        level = "1";
                        sectionid = this.secOptions.find((item) => {
                            return item.key === this.chooseGridFormdata.sectionid
                        }).value;
                    }

                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/gridGeneral/modifyPolygon',
                        method: 'get',
                        // data: JSON.stringify(array),
                        data: {
                            condition: JSON.stringify({
                                level: level,
                                orgId: yufp.session.user.org.code,
                                gridName: this.chooseGridFormdata.gridName,
                                sectionid: sectionid
                            })
                        },
                        callback: function (code, message, response) {
                            if (code == 0 && response.code == 0) {
                                //获取上级网格名称和ID
                                console.info(response.data);
                                var maxPolygon = {};
                                if (response.data.length > 0) {
                                    for (var i = 0; i < response.data.length; i++) {
                                        if (response.data[i].modify != undefined && response.data[i].modify == "1") {
                                            maxPolygon = response.data[i];
                                            continue;
                                        }
                                        var latitude = response.data[i].latitude.split(",");
                                        var longitude = response.data[i].longitude.split(",");
                                        var bPoints = new Array();
                                        for (let j = 0; j < latitude.length; j++) {
                                            // 百度坐标系坐标(地图中需要使用这个)
                                            var point = new BMap.Point(longitude[j], latitude[j]); //将标注点转化成地图上的点
                                            bPoints.push(point); // 添加到百度坐标数组 用于自动调整缩放级别
                                        }
                                        _this.setZoom(bPoints);//自动定位
                                        var polygon = new BMap.Polygon(bPoints, this.styleOptions);  //创建多边形
                                        map.addOverlay(polygon);   //增加多边形

                                        // if (response.data[i].modify != undefined && response.data[i].modify == "1") {
                                        //     // this.InOrOutPolygon(116.70410590477336, 39.79979372793364, this.polygon);
                                        //     console.info("response.data[i]============");
                                        //     console.info(response.data[i]);
                                        //     _this.modifyPolygon = response.data[i];
                                        //     polygon.enableEditing();
                                        //     var lineupdate = function (e) {
                                        //         var path = e.target.Ao;//Array<Point> 返回多边型的点数组
                                        //         var lngLsit = "";
                                        //         var latLsit = "";
                                        //         for (var i = 0; i < path.length; i++) {
                                        //             console.log("lng:" + path[i].lng + "\n lat:" + path[i].lat);
                                        //             if (i > 0) {
                                        //                 lngLsit += ',';
                                        //                 latLsit += ',';
                                        //             }
                                        //             latLsit += path[i].lat;
                                        //             lngLsit += path[i].lng;
                                        //         }
                                        //         _this.modifyPolygon.longitude = lngLsit;
                                        //         _this.modifyPolygon.latitude = latLsit;
                                        //     };
                                        //     var dbclick = function (e) {
                                        //         _this.dialogStatus = 'update';
                                        //         _this.gridVisible = true;
                                        //         _this.createGridFormdata.longitude = _this.modifyPolygon.longitude;
                                        //         _this.createGridFormdata.latitude = _this.modifyPolygon.latitude;
                                        //         _this.gridModifyName='';
                                        //         _this.gridModifyId=_this.modifyPolygon.id;
                                        //         if(_this.modifyPolygon.gridlevel == "1"){
                                        //             _this.createGridFormdata.gridNameOrg= _this.modifyPolygon.orgid;
                                        //             _this.createGridFormdata.gridName= _this.modifyPolygon.gridname;
                                        //             _this.gridModifyName= _this.modifyPolygon.gridname;
                                        //             _this.createGridFormdata.sectionid= _this.modifyPolygon.sectionid;
                                        //         }else{
                                        //             _this.createGridFormdata.gridName= _this.modifyPolygon.gridname;
                                        //         }
                                        //         console.info("_this.modifyPolygon=========================");
                                        //         console.info(_this.modifyPolygon);
                                        //         // //保存更新数据
                                        //         // var model = {};
                                        //         // model.id = _this.modifyPolygon.id;
                                        //         // model.lon = _this.modifyPolygon.longitude;
                                        //         // model.lat = _this.modifyPolygon.latitude;
                                        //         // model.lat = _this.modifyPolygon.gridname;
                                        //         // //保存修改的内容
                                        //         // yufp.service.request({
                                        //         //     url: backend.msmFrontWebService + '/api/gridGeneral/updataPolygonInfo',
                                        //         //     method: 'post',
                                        //         //     // data: JSON.stringify(array),
                                        //         //     data: model,
                                        //         //     callback: function (code, message, response) {
                                        //         //         if (code == 0 && response.code == 0) {
                                        //         //             console.info("保存成功");
                                        //         //             _this.removeOverlay();
                                        //         //             _this.initData();
                                        //         //         } else {
                                        //         //             console.info("失败");
                                        //         //         }
                                        //         //     }
                                        //         // });
                                        //     };
                                        //     polygon.addEventListener('lineupdate', lineupdate);
                                        //     polygon.addEventListener('rightclick', dbclick);
                                        //     // polygon.getMap().getPanes().markerPane.style.zIndex = 500;
                                        // }
                                    }
                                    var latitude = maxPolygon.latitude.split(",");
                                    var longitude = maxPolygon.longitude.split(",");
                                    var bPoints = new Array();
                                    for (let j = 0; j < latitude.length; j++) {
                                        // 百度坐标系坐标(地图中需要使用这个)
                                        var point = new BMap.Point(longitude[j], latitude[j]); //将标注点转化成地图上的点
                                        bPoints.push(point); // 添加到百度坐标数组 用于自动调整缩放级别
                                    }
                                    _this.setZoom(bPoints);//自动定位
                                    var polygon = new BMap.Polygon(bPoints, this.styleOptions);  //创建多边形
                                    map.addOverlay(polygon);   //增加多边形
                                    _this.modifyPolygon = maxPolygon;
                                    console.info("_this.modifyPolygon===================");
                                    console.info(_this.modifyPolygon);
                                        polygon.enableEditing();
                                        var lineupdate = function (e) {
                                            var path = e.target.Ao;//Array<Point> 返回多边型的点数组
                                            var lngLsit = "";
                                            var latLsit = "";
                                            for (var i = 0; i < path.length; i++) {
                                                console.log("lng:" + path[i].lng + "\n lat:" + path[i].lat);
                                                if (i > 0) {
                                                    lngLsit += ',';
                                                    latLsit += ',';
                                                }
                                                latLsit += path[i].lat;
                                                lngLsit += path[i].lng;
                                            }
                                            _this.modifyPolygon.longitude = lngLsit;
                                            _this.modifyPolygon.latitude = latLsit;
                                        };
                                        var dbclick = function (e) {
                                            _this.dialogStatus = 'update';
                                            _this.gridVisible = true;
                                            _this.createGridFormdata.longitude = _this.modifyPolygon.longitude;
                                            _this.createGridFormdata.latitude = _this.modifyPolygon.latitude;
                                            _this.gridModifyName='';
                                            _this.gridModifyId=_this.modifyPolygon.tableId;
                                            if(_this.modifyPolygon.gridlevel == "1"){
                                                _this.createGridFormdata.gridNameOrg= _this.modifyPolygon.orgid;
                                                _this.createGridFormdata.gridName= _this.modifyPolygon.gridname;
                                                _this.gridModifyName= _this.modifyPolygon.gridname;
                                                _this.createGridFormdata.sectionid= _this.modifyPolygon.sectionid;
                                            }else{
                                                _this.createGridFormdata.gridName= _this.modifyPolygon.gridname;
                                                _this.createGridFormdata.gridType= _this.modifyPolygon.gridscenetype;
                                            }
                                        };
                                        polygon.addEventListener('lineupdate', lineupdate);
                                        polygon.addEventListener('rightclick', dbclick);
                                }
                                _this.chooseGridVisible = false;
                            } else {
                                _this.chooseGridVisible = false;
                                console.info("失败");
                            }
                        }
                    });
                },
                //根据角色加载不同的下拉内容，且客户经理角色无法修改
                requireGridData: function () {

                },
                //取第一个点去后台判断是哪个网格内的二级网格，取出上级网格ID，并写入到上级网格中去 要区分客户经理和支行、行长
                checkGripOnPolygon: function (lon, lat) {
                    var _this = this;
                    var level = null;
                    if (yufp.session.roles[0].code == 'R0001' || yufp.session.roles[0].code == 'R0002') {
                        level = "2";
                    } else {
                        level = "1";
                    }
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/gridGeneral/checkGripOnPolygon',
                        method: 'get',
                        // data: JSON.stringify(array),
                        data: {
                            condition: JSON.stringify({
                                level: level,
                                userId: yufp.session.userId,
                                orgId: yufp.session.user.org.code,
                                lon: lon,
                                lat: lat
                            })
                        },
                        callback: function (code, message, response) {
                            if (code == 0 && response.code == 0) {
                                //获取上级网格名称和ID
                                console.info(response.data);
                                if (response.data.length > 0) {
                                    _this.createGridFormdata.upGridId = response.data[0].id;
                                    _this.createGridFormdata.upGrid = response.data[0].gridName;
                                    //建筑物点的构建
                                    _this.createFormdata.upGridId = response.data[0].id;
                                    _this.createFormdata.upGrid = response.data[0].gridName;
                                    console.info("成功---------");
                                }
                            } else {
                                console.info("失败");
                            }
                        }
                    });
                },
                initData: function () {
                    /*
                        根据不同角色等级查看不同的网格展示
                        总行->1级->展示所有已画的一级网格并标注网格名称在地图上 ->网格级别：一级 灰色；上级网格：总行 灰色；网格名名称：通过选择支行来带入；经纬度：带入 灰色
                        分行->2级->无此权限
                        支行->3级->展示此支行的一级网格及此一级网格下的已画的二级网格 ->网格级别：二级 灰色；上级网格：其所在的一级网格（多个的时候需根据绘制的点判断去后台取二级网格的名称）灰色；网格名名称：通过选择支行来带入；经纬度：带入 灰色；网格类型：选择
                        行长->4级->展示此支行的一级网格及此一级网格下的已画的二级网格->网格级别：二级 灰色；上级网格：其所在的一级网格（多个的时候需根据绘制的点判断去后台取二级网格的名称）灰色；网格名名称：通过选择支行来带入；经纬度：带入 灰色；网格类型：选择
                        客户经理->展示分给此客户经理的二级网格及已经绘制的建筑物点 ->网格级别：三级 灰色；上级网格：其所在的一级网格（多个的时候需根据绘制的点判断去后台取二级网格的名称）灰色；场景网格属性：选择；建筑物名称输入；经纬度:带入 不可修改
                    */
                    if (yufp.session.roles[0].code == 'R0008' || yufp.session.roles[0].code == 'R0007') {
                        this.requestGrid(yufp.session.user.org.code, yufp.session.userId, backend.msmFrontWebService + '/api/gridGeneral/onlyOneLevelGrid');
                        //定值
                        this.createGridFormdata.gridLevel = '1';
                        this.createGridFormdata.upGrid = '总行';
                        this.createGridFormdata.upGridId = '0';
                        this.showGridNameOrg = true;
                        this.showGridName = false;
                        this.showGridType = false;
                        this.showSec = true;
                        this.girdInfoParams.condition=JSON.stringify({
                            roleLevel: '1',
                            userOrgId: yufp.session.user.org.code,
                            userId: yufp.session.userId
                        });
                        console.info("this.createGridFormdata====================");
                        console.info(this.createGridFormdata);
                    } else if (yufp.session.roles[0].code == 'R0006') {

                    } else if (yufp.session.roles[0].code == 'R0005' || yufp.session.roles[0].code == 'R0003' || yufp.session.roles[0].code == 'R0004') {
                        //传入支行查询一级网格及二级网格
                        // console.info(yufp.session.orgId);
                        console.info(yufp.session.user.org.code)
                        this.requestGrid(yufp.session.user.org.code, yufp.session.userId, backend.msmFrontWebService + '/api/gridGeneral/oneLevelGridByOrgId');
                        //定值
                        this.createGridFormdata.gridLevel = '2';
                        // this.createGridFormdata.upGrid='总行';
                        // this.createGridFormdata.upGridId='0';
                        this.showGridNameOrg = false;
                        this.showGridName = true;
                        this.showGridType = true;
                        this.girdInfoParams.condition=JSON.stringify({
                            roleLevel: '2',
                            userOrgId: yufp.session.user.org.code,
                            userId: yufp.session.userId
                        });
                    } else {
                        //传入支行查询二级网格及建筑物点

                        this.requestGrid(yufp.session.user.org.code, yufp.session.userId, backend.msmFrontWebService + '/api/gridGeneral/twoLevelGridByUserId');
                        //定值
                        this.createFormdata.gridLevel = '3';
                        // this.createGridFormdata.upGrid='总行';
                        // this.createGridFormdata.upGridId='0';
                        this.showGridNameOrg = false;
                        this.showGridName = true;
                        this.showGridType = true;
                        this.girdInfoParams.condition=JSON.stringify({
                            roleLevel: '3',
                            userOrgId: yufp.session.user.org.code,
                            userId: yufp.session.userId
                        });
                        this.unitNumberDis=false;
                        this.unitPriceDis=false;
                        console.info(this.unitNumberDis+"---------------------------------------------")
                    }
                },
                initSelectData: function () {
                    /*
                        根据不同角色等级查看不同的网格展示（是否智能修改自己画的网格）
                        总行->1级->下拉展示1级网格
                        分行->2级->无此权限
                        支行->3级->展示此支行的已画的二级网格
                        行长->4级->展示此支行的已画的二级网格
                        客户经理->无此权限
                    */
                    if (yufp.session.roles[0].code == 'R0008' || yufp.session.roles[0].code == 'R0007') {
                        this.requestGridAndChangeSelect(yufp.session.user.org.code, yufp.session.userId, "1", backend.msmFrontWebService + '/api/gridGeneral/onlyOneLevelGridModify');

                    } else if (yufp.session.roles[0].code == 'R0005' || yufp.session.roles[0].code == 'R0003' || yufp.session.roles[0].code == 'R0004') {
                        //传入支行查询一级网格及二级网格
                        this.requestGridAndChangeSelect(yufp.session.user.org.code, yufp.session.userId, "2", backend.msmFrontWebService + '/api/gridGeneral/onlyTwoLevelGridModify');
                    }
                },
                //请求onlyOneLevelGrid，仅显示所有一级网格
                requestGrid: function (orgId, userId, url) {
                    var _this = this;
                    yufp.service.request({
                        url: url,
                        method: 'get',
                        // data: JSON.stringify(array),
                        data: {
                            condition: JSON.stringify({
                                orgId: orgId,
                                userId: userId
                            })
                        },
                        callback: function (code, message, response) {
                            if (code == 0 && response.code == 0) {
                                _this.initLatLng(response.data, map);//构建所有一级网格

                                console.info("成功");
                            } else {
                                console.info("失败");
                            }
                        }
                    });
                },
                requestGridAndChangeSelect: function (orgId, userId, level, url) {
                    var _this = this;
                    yufp.service.request({
                        url: url,
                        method: 'get',
                        // data: JSON.stringify(array),
                        data: {
                            condition: JSON.stringify({
                                orgId: orgId,
                                userId: userId
                            })
                        },
                        callback: function (code, message, response) {
                            if (code == 0 && response.code == 0) {
                                console.info("response.data");
                                console.info(response.data);
                                var options = [];
                                if (response.data.length > 0) {
                                    var infos = response.data;
                                    infos.forEach(function (item) {
                                        console.info("===================================");
                                        console.info(item);
                                        var option = {};
                                        if (level == "1") {
                                            option.key = item.orgid;
                                            option.value = item.gridname;
                                            options.push(option);
                                        }else{
                                            if(item.gridlevel == "2"){
                                                option.key = item.id;
                                                option.value = item.gridname;
                                                options.push(option);
                                            }
                                        }
                                        // option.value = item.gridname;
                                        // options.push(option);
                                    });
                                }
                                _this.stsOptions = options;
                                console.info("成功");
                            } else {
                                console.info("失败");
                            }
                        }
                    });
                },
                onSelectedChange: function (value) {
                    var _this = this;
                    console.log(value);
                    // console.log(_this.stsOptions.find((item) => {
                    //     return item.key === value
                    // }).value);
                    // console.info('--------------------------------------')
                    // console.info(_this.stsOptions)
                    // console.info(_this.stsOptions.find((item) => {
                    //     return item.key === value
                    // }))
                    if (value == null || value === '') {
                        return;
                    }
                    var gridName = _this.stsOptions.find((item) => {
                        return item.key === value
                    }).value;
                    //根据网格Name查询网格备注
                    yufp.service.request({
                        url: backend.msmFrontWebService + '/api/gridGeneral/querySecByGridName',
                        method: 'get',
                        data: {
                            condition: JSON.stringify({
                                gridname: gridName,
                                orgId: value
                            })
                        },
                        callback: function (code, message, response) {
                            if (code == 0 && response.code == 0) {
                                var options = [];
                                if (response.data.length > 0) {
                                    var infos = response.data;
                                    infos.forEach(function (item) {
                                        console.info("++++++++++++++++++++++");
                                        console.info(item);
                                        var option = {};
                                        option.key = item.tableId;
                                        option.value = item.sectionid;
                                        options.push(option);
                                    });
                                }
                                _this.secOptions = options;
                            } else {
                                console.info("失败");
                            }
                        }
                    });

                },
                //解析网格后台经纬度 并添加到地图
                initLatLng: function (data, map) {
                    this.removeOverlay();
                    this.markPolygonInfo = [];
                    for (let i = 0; i < data.length; i++) {
                        //如果是建筑物点就执行下面逻辑并break掉
                        console.info("------------------------------");
                        console.info(data[i].gridlevel);
                        console.info("------------------------------");
                        if (data[i].gridlevel == "3") {//对点进行操作
                            console.info("进入data[i].gridlevel == \"3\"");//获取到一级网格点的信息
                            var pointD = new BMap.Point(data[i].longitude, data[i].latitude);
                            map.centerAndZoom(pointD, 14);
                            // 创建点标记
                            var marker = new BMap.Marker(pointD);
                            // this.addListeThird(marker);
                            map.addOverlay(marker);

                            // var label1 = new BMap.Label(, { offset: new BMap.Size(-15, 2) });
                            // marker.setLabel(label1);
                            // label1.setStyle({
                            //     color: "red",
                            //     fontSize: "9px",
                            //     backgroundColor: "0.05",
                            //     border: "0",
                            //     fontWeight: "bold"
                            // });
                            //点击弹出信息
                            marker.addEventListener(
                                "click",
                                function () {
                                    var sContent =
                                        "<form method=\'post\' action=\'\'>" +
                                        "<table>" +
                                        "<tr>" +
                                        "<td><b>名称：</b>" +
                                        "<input type=\'text\' name=\'Name\' style=\'margin-top:10px;width:150px\' value="+data[i].gridname+">" +
                                        "</td><tr></tr>";
                                    sContent+= "</tr>" +
                                        "</talbe>" +
                                        "</form>";
                                    var opts = {
                                        enableMessage: false
                                    };
                                    var infoWindow = new BMap.InfoWindow(sContent, opts);
                                    this.openInfoWindow(infoWindow);
                                });

                            continue;
                        }
                        var latitude = data[i].latitude.split(",");
                        var longitude = data[i].longitude.split(",");
                        var bPoints = new Array();
                        for (let j = 0; j < latitude.length; j++) {
                            // 百度坐标系坐标(地图中需要使用这个)
                            var point = new BMap.Point(longitude[j], latitude[j]); //将标注点转化成地图上的点
                            bPoints.push(point); // 添加到百度坐标数组 用于自动调整缩放级别
                        }
                        this.setZoom(bPoints);//自动定位
                        var polygon = null;
                        if(data[i].gridlevel == "1"){
                            polygon = new BMap.Polygon(bPoints, this.styleOptions);  //创建多边形
                        }else{
                            polygon = new BMap.Polygon(bPoints, this.styleOptionsLevel2);  //创建多边形
                        }

                        //获取多边形中间点---------------------------
                        var x = 0,
                            y = 0;
                        var path = polygon.getPath();//返回多边型的点数组；ply是多边形覆盖物
                        for(var k = 0;k<path.length;k++){
                            x=x+ parseFloat(path[k].lng);
                            y=y+ parseFloat(path[k].lat);
                        }
                        x=x/path.length;
                        y=y/path.length;
                        //获取多边形中间点---------------------------

                        //添加标签----------------------------------------
                        // var tagMarkerIcon = new BMap.Icon("http://api.map.baidu.com/img/markers.png", new BMap.Size(23, 25), {
                        var tagMarkerIcon = new BMap.Icon("http://192.168.55.58:8081/api.map.baidu.com/img/markers.png", new BMap.Size(23, 25), {
                            imageOffset: new BMap.Size(0, 0 - 13 * 25) // 设置图片偏移
                        });
                        var marker1 = new BMap.Marker(new BMap.Point(x, y), { icon: tagMarkerIcon });
                        var label1 = new BMap.Label(data[i].gridname, { offset: new BMap.Size(-15, 2) });
                        marker1.setLabel(label1);
                        label1.setStyle({
                            color: "red",
                            fontSize: "9px",
                            backgroundColor: "0.05",
                            border: "1",
                            fontWeight: "bold",
                            borderStyle: "solid"
                        });
                        //点击弹出信息
                        marker1.addEventListener(
                            "click",
                            function () {
                                var sContent =
                                    "<form method=\'post\' action=\'\'>" +
                                    "<table>" +
                                    "<tr>" +
                                    "<td><b>名称：</b>" +
                                    "<input type=\'text\' name=\'Name\' style=\'margin-top:10px;width:150px\' value="+data[i].gridname+">" +
                                    "</td><tr></tr>";
                                if (data[i].gridlevel == "1") {
                                    sContent+="<tr><td style=\'text-align:right;\'>" +
                                        "<b>备注：</b>" +
                                        "<input type=\'text\' name=\'Name\' style=\'margin-top:10px;width:150px\' value="+data[i].sectionid+">" +
                                        "</td>";
                                }
                                sContent+= "</tr>" +
                                    "</talbe>" +
                                    "</form>";
                                var opts = {
                                    enableMessage: false
                                };
                                var infoWindow = new BMap.InfoWindow(sContent, opts);
                                this.openInfoWindow(infoWindow);
                            });
                        map.addOverlay(marker1);
                        //添加标签----------------------------------------
                        polygon.setFillOpacity(0.5 + (i + 1) * 0.00001);
                        var obj = new Object();
                        obj = data[i];
                        obj.fillOpacity = 0.5 + (i + 1) * 0.00001;
                        this.markPolygonInfo.push(obj);

                        console.info(this.markPolygonInfo);
                        console.info("-----------------------------------------------------------------------");
                        // if(obj.gridlevel == "1"){
                        //     this.addListe(polygon);
                        // }else{
                        //     this.addListeTwo(polygon);
                        // }
                        map.addOverlay(polygon);
                    }
                },
                theLocation: function () {
                    console.info("KKKKKKKKKKKK");
                    // var city = document.getElementById("cityName").value;
                    if (this.cityName != "") {
                        this.analysis(this.cityName);      // 用城市名设置地图中心点
                    }
                },
                // showMarkDio: function (){
                //   this.configType = 'CREATEB';
                //   this.configdialogVisible = true;
                //   this.$nextTick(function () {
                //     this.$refs.configform.resetFields();
                //     yufp.extend(this.$refs.configform.formModel, this.bizModel);
                //   });
                // },
                initDrawingManager: function (flag) {
                    var _this = this;
                    //实例化鼠标绘制工具
                    // console.info(!this.drawingManager);
                    if (!this.drawingManager) {
                        this.drawingManager = new BMapLib.DrawingManager(map, {
                            isOpen: true, //是否开启绘制模式
                            enableDrawingTool: flag, //是否显示工具栏
                            drawingMode: BMAP_DRAWING_POLYGON,//绘制模式  多边形
                            drawingToolOptions: {
                                anchor: BMAP_ANCHOR_TOP_RIGHT, //位置
                                offset: new BMap.Size(100, 10), //偏离值
                                drawingModes: [
                                    BMAP_DRAWING_MARKER,
                                    BMAP_DRAWING_POLYGON
                                ]
                            },
                            // circleOptions: styleOptions, //圆的样式
                            // polylineOptions: styleOptions, //线的样式
                            polygonOptions: this.createGridFormdata.gridLevel=='2'?this.styleOptionsLevel2:this.styleOptions, //多边形的样式
                            // rectangleOptions: styleOptions //矩形的样式
                        });
                        var polygoncomplete = function (e) {
                            console.log(e);
                            console.log("---------------------------------");
                            console.log(yufp.session.roles[0].code);

                            if (yufp.session.roles[0].code == 'R0001' || yufp.session.roles[0].code == 'R0002') {
                                _this.$message.warning("您无权限创建一级或二级网格");
                                _this.removeOverlay();
                                _this.initData();
                                console.info(_this.showGridNameOrg);
                                console.info(_this.showGridType);
                                return;
                            }
                            // console.log(e.type);
                            // console.log(e.point);
                            // if(e.type=='markercomplete'){
                            //   console.log(e.point);
                            // }else{
                            //   overlays.push(e.overlay);
                            _this.dialogStatus = 'create';
                            _this.gridVisible = true;
                            var path = e.Ao;//Array<Point> 返回多边型的点数组
                            var lngLsit = "";
                            var latLsit = "";


                            //取第一个点去后台判断是哪个网格内的二级网格，取出上级网格ID，并写入到上级网格中去
                            _this.checkGripOnPolygon(path[0].lng, path[0].lat);

                            for (var i = 0; i < path.length; i++) {
                                if (i > 0) {
                                    lngLsit += ',';
                                    latLsit += ',';
                                }
                                latLsit += path[i].lat;
                                lngLsit += path[i].lng;
                                // console.log("lng:"+path[i].lng+"\n lat:"+path[i].lat);
                            }
                            console.log("lng:" + lngLsit + "\n lat:" + latLsit);
                            _this.createGridFormdata.longitude = lngLsit;
                            _this.createGridFormdata.latitude = latLsit;
                            // }
                        };
                        var markercomplete = function (e) {
                            // showMarkDio();
                            // _this.configType = 'CREATEB';
                            console.log("---------------------------------");
                            console.log(yufp.session.roles[0].code);
                            if (yufp.session.roles[0].code != 'R0001' && yufp.session.roles[0].code != 'R0002' && yufp.session.roles[0].code != 'R0009') {
                                _this.$message.warning("建筑物点创建请交由客户经理完成！");
                                _this.removeOverlay();
                                _this.initData();
                                return;
                            }
                            _this.configdialogVisible = true;
                            console.info("_this.configdialogVisible");
                            console.info(_this.configdialogVisible);
                            console.info("_this.configdialogVisible end");
                            console.log(e);
                            console.log(e.type);
                            console.log(e.point);
                            //取第一个点去后台判断是哪个网格内的二级网格，取出上级网格ID，并写入到上级网格中去
                            _this.checkGripOnPolygon(e.point.lng, e.point.lat);
                            _this.createFormdata.longitude = e.point.lng;
                            _this.createFormdata.latitude = e.point.lat;
                        };
                        // function showMarkDio(){
                        // this.configType = 'CREATEB';

                        //  this.$nextTick(function () {
                        //   this.$refs.configform.resetFields();
                        //   yufp.extend(this.$refs.configform.formModel, this.bizModel);
                        // });
                        // };
                        // this.drawingManager.addEventListener('polygoncomplete', overlaycomplete);
                        this.drawingManager.addEventListener('polygoncomplete', polygoncomplete);
                        this.drawingManager.addEventListener('markercomplete', markercomplete);
                    }//else{

                    // console.info(this.drawingManager._drawingTool)
                    // delete this.drawingManager._drawingTool;
                    //}

                    // drawingManager.close();
                    // drawingManager.hidden();
                    //添加鼠标绘制工具监听事件，用于获取绘制结果
                    // var overlays = [];


                },
                showTool: function () { //根据点绘制多边形方法
                    // this.removeOverlay();
                    this.initDrawingManager(this.flag);
                    // this.initDrawingManager(this.flag);
                    // // overlays.push(polygon); //是否把该图像加入到编辑和删除行列
                    // // btn.setAttribute('disabled','false');
                    // showText();
                },
                analysis: function (addressMap) {
                    // //创建地址解析器实例
                    // var myGeo = new BMap.Geocoder();
                    // // 将地址解析结果显示在地图上，并调整地图视野
                    // myGeo.getPoint(address, function(point){
                    //     if(point){
                    //         map.centerAndZoom(point, 14);
                    //         map.addOverlay(new BMap.Marker(point, {title: address}))
                    //     }else{
                    //         alert('您选择的地址没有解析到结果！');
                    //     }
                    // }, address)
                    var local = new BMap.LocalSearch(map, {
                        //智能搜索
                        onSearchComplete: function () {
                            var j = local.getResults().getPoi(0).point.lng //获取第一个智能搜索的结果
                            var w = local.getResults().getPoi(0).point.lat //获取第一个智能搜索的结果
                            // console.log(j + '-' + w)
                            var a = map.panTo(new BMap.Point(j, w)) //地图中心点转移到第一条搜索结果
                            // var mPoint = new BMap.Point((j, w), 20)
                            var marker1 = new BMap.Marker(new BMap.Point(j, w)) // 创建标注
                            map.clearOverlays()
                            map.addOverlay(marker1) // 将标注添加到地图
                            marker1.onclick = function () {
                                window.open(
                                    'http://api.map.baidu.com/geocoder?address=' +
                                    addressMap +
                                    '&output=html&src=webapp.baidu.openAPIdemo'
                                )
                            }
                        },
                    })
                    local.enableAutoViewport(true);
                    local.search(addressMap);

                },
                editPolygon: function () { //根据点绘制多边形方法
                    this.chooseGridFormdata.gridName = "";
                    this.chooseGridFormdata.sectionid = "";
                    if (yufp.session.roles[0].code == 'R0001' || yufp.session.roles[0].code == 'R0002') {
                        this.$message.warning("客户经理没有网格修改权限！");
                        this.removeOverlay();
                        this.initData();
                        return;
                    }
                    this.stsOptions = null;
                    this.secOptions = null;
                    this.initSelectData();

                    this.flag = false;
                    console.info("this.flag::::::" + this.flag);
                    console.info(this.drawingManager);
                    this.removeOverlay();
                    this.chooseGridVisible = true;
                    // var styleOptions = {
                    //     strokeColor: "red",    //边线颜色。
                    //     fillColor: "red",      //填充颜色。当参数为空时，圆形将没有填充效果。
                    //     strokeWeight: 3,       //边线的宽度，以像素为单位。
                    //     strokeOpacity: 0.8,	   //边线透明度，取值范围0 - 1。
                    //     fillOpacity: 0.6,      //填充的透明度，取值范围0 - 1。
                    //     strokeStyle: 'solid' //边线的样式，solid或dashed。
                    // }
                    // // 百度坐标系坐标(地图中需要使用这个)
                    // var bPoints = new Array();
                    // //后台数据
                    // var data_info = [
                    //     [116.70410590477336, 39.79979372793364],
                    //     [115.97971234152713, 39.56701661452678],
                    //     [115.96361470678833, 39.01661208380118],
                    //     [116.96166806059423, 39.44765708787029],
                    //
                    //     [116, 39]
                    // ];
                    // for (var i = 0; i < data_info.length; i++) {
                    //     var point = new BMap.Point(data_info[i][0], data_info[i][1]); //将标注点转化成地图上的点
                    //     bPoints.push(point); // 添加到百度坐标数组 用于自动调整缩放级别
                    //     // var marker = new BMap.Marker(point);  // 创建标注
                    //     // var content = data_info[i][2];
                    //     // map.addOverlay(marker);               // 将标注添加到地图中
                    //     // addClickHandler(content,marker);
                    // }
                    //
                    // this.setZoom(bPoints);//自动定位
                    // this.polygon = new BMap.Polygon(bPoints, styleOptions);  //创建多边形
                    // this.InOrOutPolygon(116.70410590477336, 39.79979372793364, this.polygon);
                    // // this.polygon = new BMap.Polygon([
                    // //   new BMap.Point(115.97971234152713,39.56701661452678),
                    // //   new BMap.Point(115.96361470678833,39.01661208380118),
                    // //   new BMap.Point(116.96166806059423,39.44765708787029),
                    // //   new BMap.Point(116.70410590477336,39.79979372793364),
                    // //   new BMap.Point(116,39)
                    // // ], styleOptions);  //创建多边形
                    // map.addOverlay(this.polygon);   //增加多边形
                    // this.polygon.enableEditing();
                    // var lineupdate = function (e) {
                    //     var path = e.target.Ao;//Array<Point> 返回多边型的点数组
                    //     for (var i = 0; i < path.length; i++) {
                    //         console.log("lng:" + path[i].lng + "\n lat:" + path[i].lat);
                    //     }
                    // };
                    // this.polygon.addEventListener('lineupdate', lineupdate);
                },
                removeOverlay: function () {
                    map.clearOverlays();
                },
                sureConfig: function () {
                    var _this = this;
                    _this.loadingA = true;
                    var model = {};
                    // console.info(this.createGridFormdata);
                    yufp.clone(_this.createFormdata, model);
                    // if (yufp.session.roles[0].code == 'R0008' || yufp.session.roles[0].code == 'R0007') {
                    //     model.upGridId = '0';
                    // }else if (yufp.session.roles[0].code == 'R0005' || yufp.session.roles[0].code == 'R0003' || yufp.session.roles[0].code == 'R0004') {

                    model.upOrgId = yufp.session.org.code;
                    model.userName = yufp.session.userName;
                    model.orgId = yufp.session.org.code;
                    console.info(yufp.session.org.code);
                    console.info("+++++++++++++");
                    console.info(model);
                    // }
                    // console.info(_this.createGridFormdata.upGridId);
                    // console.info(this.createGridFormdata.upGridId);
                    // console.info(this.createGridFormdata);
                    // console.info(model);
                    yufp.service.request({
                        method: 'POST',
                        url: '/api/gridGeneral/saveGridData',
                        data: model,
                        callback: function (code, message, response) {
                            if (code == 0 && response.data > 0) {
                                _this.$message({message: '创建成功', type: 'success'});
                                _this.configdialogVisible = false;
                                _this.createFormdata = {};
                                _this.initData();
                            } else {
                                _this.$message({message: '创建失败', type: 'error'});
                            }
                            _this.loadingA=false;
                        }
                    });
                },
                saveGrid: function () {
                    var _this = this;
                    _this.loadingB = true;
                    var model = {};
                    // console.info(this.createGridFormdata);
                    yufp.clone(_this.createGridFormdata, model);
                    model.userName = yufp.session.userName;
                    if (yufp.session.roles[0].code == 'R0008' || yufp.session.roles[0].code == 'R0007') {
                        model.upGridId = '0';
                    } else if (yufp.session.roles[0].code == 'R0005' || yufp.session.roles[0].code == 'R0003' || yufp.session.roles[0].code == 'R0004') {

                        model.upOrgId = yufp.session.org.code;
                        model.orgId = yufp.session.org.code;
                        console.info(yufp.session.org.code);
                        console.info("+++++++++++++")
                        console.info(model)
                    }
                    // console.info(_this.createGridFormdata.upGridId);
                    // console.info(this.createGridFormdata.upGridId);
                    // console.info(this.createGridFormdata);
                    // console.info(model);
                    if(_this.dialogStatus == 'create'){
                        yufp.service.request({
                            method: 'POST',
                            url: '/api/gridGeneral/saveGridData',
                            data: model,
                            callback: function (code, message, response) {
                                if (code == 0 && response.data > 0) {
                                    _this.$message({message: '创建成功', type: 'success'});
                                    _this.gridVisible = false;
                                    _this.createGridFormdata = {};
                                    _this.initData();
                                } else {
                                    _this.$message({message: '创建失败', type: 'error'});
                                }
                                _this.loadingB = false;
                            }
                        });
                    }else{
                        //保存更新数据
                        //保存修改的内容
                        model.gridname=_this.createGridFormdata.gridName;
                        model.id=_this.gridModifyId;
                        if(_this.createGridFormdata.gridLevel == '1'){
                            model.gridname=_this.gridModifyName;
                        }

                        console.info("===================================");
                        console.info(_this.createGridFormdata);
                        console.info(model);
                        yufp.service.request({
                            url: backend.msmFrontWebService + '/api/gridGeneral/updataPolygonInfo',
                            method: 'post',
                            // data: JSON.stringify(array),
                            data: model,
                            callback: function (code, message, response) {
                                if (code == 0 && response.code == 0) {
                                    _this.$message({message: '修改成功', type: 'success'});
                                    _this.gridVisible = false;
                                    _this.removeOverlay();
                                    _this.initData();
                                } else {
                                    console.info("失败");
                                }
                                _this.loadingB = false;
                            }
                        });
                        this.chooseGridFormdata.gridName = "";
                        this.chooseGridFormdata.sectionid = "";
                    }

                },
                getZoom: function (list) {
                    var point0 = new BMap.Point(list[0].lon, list[0].lat);
                    var maxDistance = 0;
                    for (var i = 1; i < list.length; i++) {
                        var pointX = new BMap.Point(list[i].lon, list[i].lat);
                        var distance = map.getDistance(point0, pointX).toFixed(1);
                        if (distance > maxDistance) {
                            maxDistance = distance
                        }
                    }
                    maxDistance = maxDistance * 2;//计算距离中心点最远点和中心点距离的2倍
                    var zoom = ["50", "100", "200", "500", "1000", "2000", "5000", "10000", "20000", "25000", "50000", "100000", "200000", "500000", "1000000", "2000000"]//级别18到3。
                    // var pointA = new BMap.Point(maxLng,maxLat);  // 创建点坐标A
                    // var pointB = new BMap.Point(minLng,minLat);  // 创建点坐标B
                    // var distance = map.getDistance(pointA,pointB).toFixed(1);  //获取两点距离,保留小数点后两位
                    for (var i = 0, zoomLen = zoom.length; i < zoomLen; i++) {
                        if (zoom[i] - distance > 0) {
                            return 18 - i;//之所以会多3，是因为地图范围常常是比例尺距离的10倍以上。所以级别会增加3。
                        }
                    }
                    ;
                },
                // 根据点的数组自动调整缩放级别
                setZoom: function (bPoints) {
                    var view = map.getViewport(eval(bPoints));
                    var mapZoom = view.zoom;
                    var centerPoint = view.center;
                    map.centerAndZoom(centerPoint, mapZoom);
                },
                /**
                 * 判断两多变形是否存在点与区域的包含关系(A的点在B的区域内或B的点在A的区域内)
                 */
                // isPointInPolygonBidirectional: function (plyA, plyB) {
                //   const [pA, pB] = [[], []];
                //   plyA.forEach((item) => {
                //       pA.push(new BMap.Point(item.lng, item.lat));
                //   });
                //   plyB.forEach((item) => {
                //       pB.push(new BMap.Point(item.lng, item.lat));
                //   });
                //   let [a, b] = [false, false];
                //   a = pA.some(item => BMapLib.GeoUtils.isPointInPolygon(item, new BMap.Polygon(pB)));
                //   if (!a) {
                //       b = pB.some(item => BMapLib.GeoUtils.isPointInPolygon(item, new BMap.Polygon(pA)));
                //   }
                //   return a || b;
                // },
                /**
                 * 判断点是否在区域内
                 */
                InOrOutPolygon: function (lng, lat, ply) {
                    var pt = new BMap.Point(lng, lat);
                    var result = BMapLib.GeoUtils.isPointInPolygon(pt, ply);
                    if (result == true) {
                        console.info("3333333333333333 :   " + "在区域范围内");
                    } else {
                        console.info("3333333333333333 :   " + "在区域范围外");
                    }
                },
                handleClick: function () {

                },
                getOrgID: function (row) {
                    var _this = this;
                    _this.createGridFormdata.orgId = '';
                    var orgId = row.orgId;
                    console.info(orgId);
                    console.info(row.orgName);
                    _this.createGridFormdata.orgId = orgId;
                    _this.createGridFormdata.gridName = row.orgName;
                },
            }
        });
    };

    // 消息处理
    exports.onmessage = function (type, message) {

    };

    // page销毁时触发destroy方法
    exports.destroy = function (id, cite) {

    };
});
